<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class Bubble extends Sort
{

    function __construct($SourceData)
    {
        parent::__construct($SourceData);
        $this->name = "冒泡排序";
        $this->realName = "bubble";
    }

    function Sort($index)
    {
        for ($i = $this->testNumber - 1; $i > 0; $i--)
        {
            for ($j = 0; $j < $i; $j++)
            {

                if ($this->data[$index][$j] > $this->data[$index][$j + 1])
                {
                    $temp = $this->data[$index][$j];
                    $this->data[$index][$j] = $this->data[$index][$j + 1];
                    $this->data[$index][$j + 1] = $temp;
                    $this->moveCount[$index] += 3; //移动次数+3
                }
                $this->compareCount[$index] ++; //比较次数+1
            }
        }
    }

    function __toString()
    {
        return "bubble";
    }

}

$bubble = new Bubble($sourceData);
$bubble->begin();



